<?php
header("Content-type:text/html;charset=utf-8");
$t = microtime(true);

//$urls = array('http://www.baidu.com', 'http://www.qq.com', 'http://www.sina.com.cn');
$urls = [
    'http://127.0.0.1:9501/test/slow_api?r=1',
    'http://127.0.0.1:9501/test/slow_api?r=2',
    'http://127.0.0.1:9501/test/slow_api?r=3',
    'http://127.0.0.1:9501/test/slow_api?r=4',
    'http://127.0.0.1:9501/test/slow_api?r=5',
    'http://127.0.0.1:9501/test/slow_api?r=6',
    'http://127.0.0.1:9501/test/slow_api?r=7',
    'http://127.0.0.1:9501/test/slow_api?r=8',
    'http://127.0.0.1:9501/test/slow_api?r=9',
    'http://127.0.0.1:9501/test/slow_api?r=10',
];
$multi = curl_multi_init();
$curls = array();
foreach ($urls as $url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_multi_add_handle($multi, $ch);
    $curls[$url] = $ch;
}
$active = null;
do {
    $mrc = curl_multi_exec($multi, $active);
} while ($active > 0);//这个地方很多资料上写：while($mrc== CURLM_CALL_MULTI_PERFORM) 并非不正确，只是我一次工作中发现在服务器使用$mrc== CURLM_CALL_MULTI_PERFORM，怎么都不成功，总是执行超时。后来改成while($active>0);方才成功，也许是和服务器的环境有关联，我也未去研究是什么关联，如果大家碰到了类似的情况可以换换试试。如果找出了原因，希望回复一下让我知晓。
while ($active && $mrc == CURLM_OK) {//抓取执行完毕
    if (curl_multi_select($multi) == -1) {
        continue;
    }
    do {
        $mrc = curl_multi_exec($multi, $active);
    } while ($active > 0);
}
$results = array();
foreach ($curls as $i => $curl) {
    $rs = curl_multi_getcontent($curl);
    curl_multi_remove_handle($multi, $curl);
    $results[] = $rs;
}
curl_multi_close($multi);

echo microtime(true) - $t;

print_r($results);